package com.biodiv.community.controller.test;


import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.CreateCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author: tianquan
 * @date: 2025-08-13  23:31
 */
@Slf4j
@RestController
@RequestMapping("/api/test")
public class jetCacheController {

    @Value("${server.port}")
    private String port;

    @CreateCache(name = "test", expire = 3600, timeUnit = TimeUnit.SECONDS, cacheType = CacheType.BOTH)
    private Cache<String, String> cache;

    public String getCache(String key) {
        return cache.computeIfAbsent(key, k -> {
            log.info("key:{}", k);
            return "value" + k;
        });
    }

    @GetMapping("/test")
    public String test(String key) {
        log.info("port:{}", port);
        log.info("key:{}", key);
        return getCache(key);
    }


}
